package com.change.study.data.app;

import java.lang.annotation.Annotation;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;

import com.change.study.data.core.Pagination;
import com.change.study.data.entity.User;
import com.change.study.data.entity.UserRole;
import com.change.study.data.service.UserService;
import com.openyelp.annotation.RestFul;
import com.openyelp.client.RestFulClient;

public class RpcUserServiceApps {
	static String url = "http://192.168.0.188:8080/study/rpc";
    //http://192.168.0.188:8080/study/
	//http://ad.xabaoyi.com:8080/study/
	public static void main(String[] args) {
		 //TODO Auto-generated method stub
		 UserService userService =  RestFulClient.getService(url, UserService.class);

		
//		 for (int i = 0; i < 100; i++) {
//			x(userService);
//		}
		 Pagination<User> p=	 userService.findByRole(2l, 1, 10);
		 List<User>	 us=p.getList();
		 for (User user : us) {
			System.out.println(user);
		}
	}

	private static void x(UserService userService) {
		User m=new User();
		 m.setUsername("shifu"+new Random().nextInt(Integer.MAX_VALUE));
		 m.setEmail("f");
		 m.setAddDate(new Date());
		 m.setLastDate(new Date());
		 m.setIntroduction("我是一个好人");
		 m.setPassword("123456");
		 m.setPlainPassword("123456");
		 m.setName("ada"+new Random().nextInt(Integer.MAX_VALUE));
		 userService.save(m);

		// m=userService.findById(1l);
		 System.out.println(m.getRoles());
		UserRole bean=new UserRole("admin");
		 bean.setDescription("adminer");
		 bean.setId(1l);
		// roleService.save(bean);
		 userService.addRole(m.getId(), bean);
	}

	private static void xx() {
		Map<String, Object> os = ObjectFactory.get().getBeansWithAnnotation(
				RestFul.class);

		Set<String> sets = os.keySet();

		for (String key : sets) {
			Object o = os.get(key);
			Class[] classs = o.getClass().getInterfaces();
			for (Class class1 : classs) {
				Annotation xx =	class1.getAnnotation(RestFul.class);
				if(xx instanceof RestFul){
					RestFul xxx = (RestFul) xx;
					String apiname = xxx.value();
				}
		
			}
			
		}
	}

}
